<?php

namespace App\Http\Controllers\home;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use DB;

class ChangeController extends Controller
{
    public function index()
    {
        $list=DB::table('type')->get();
        $config=DB::table('config')->get();
        return view('home.user.change',['list'=>$list,'config'=>$config]);
    }
    public function update($id,Request $request)
    {
        $data=$request->except('_token','_method');
        if(md5($data['oldpass'])!=session()->get('homeuser')->pass){
            return back()->with('msg','您的旧密码输入错误');
        }
        if($data['pass']!=$data['repass']){
            return back()->with('msg','两次密码输入不一致');
        }
        $new=array('pass'=>md5($data['pass']));
        $row=DB::table('user')->where('id',$id)->update($new);
        if ($row>0) {
            return back()->with('msg','修改成功');
        }
    }
}
